<template>
	<div class="sys-org-container">
		<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" width="700px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto">
				<el-row class="fl">
					<div class="mb20 aligning1">
						<el-form-item label="编号" prop="id"
							:rules="[{ required: true, message: '机构名称不能为空', trigger: 'blur' }]">
							<el-input v-model="state.ruleForm.id" placeholder="机构名称" clearable class="input" />
						</el-form-item>
						<el-form-item label="型号">
							<el-select v-model="state.ruleForm.specification" filterable clearable class="w100">
								<el-option v-for="item in state.specifications" :key="item" :label="item" :value="item" />
							</el-select>
						</el-form-item>

					</div>
					<div class="mb20 aligning2">
						<el-form-item label="状态" :rules="[{ required: true, message: '机构名称不能为空', trigger: 'blur' }]">
							<el-radio-group v-model="state.ruleForm.status" class="ml-4">
								<el-radio :label="1">启用</el-radio>
								<el-radio :label="0">停用</el-radio>
							</el-radio-group>
						</el-form-item>

						<el-form-item label="有效限期">
							<el-date-picker v-model="state.ruleForm.effectiveDate" type="date" placeholder="Pick a day" />
						</el-form-item>
					</div>

				</el-row>
				<el-row>
					<el-form-item label="备注" prop="remark"
						:rules="[{ required: true, message: '机构名称不能为空', trigger: 'blur' }]">
						<el-input v-model="state.ruleForm.remark" placeholder="请输入备注内容" clearable type="textarea"
							style="width: 600px;" />
					</el-form-item>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="EditLocation">
import { onMounted, reactive, ref } from 'vue';

import { getAPI } from '/@/utils/axios-utils';
import { SysOrgApi, SysDictDataApi } from '/@/api-services/api';
import { UpdateOrgInput } from '/@/api-services/models';
import { Warehouse } from '/@/api-services/models/warehouse';
import { AddPalletInput } from '/@/api-services/models/add-pallet-input';

const props = defineProps({
	title: String,
});
const emits = defineEmits(['handleQuery']);
const ruleFormRef = ref();
const state = reactive({
	isShowDialog: false,
	ruleForm: {} as AddPalletInput,
	orgTypeList: [] as any,
	specifications:["600*600", "800*800"]
});

// onMounted(async () => {
// 	let resDicData = await getAPI(SysDictDataApi).apiSysDictDataDataListCodeGet('org_type');
// 	state.orgTypeList = resDicData.data.result;
// });

// 打开弹窗
const openDialog = (row: any) => {
	console.log(row);
	
	state.ruleForm = JSON.parse(JSON.stringify(row));
	state.isShowDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
	emits('handleQuery', true);
	state.isShowDialog = false;
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean) => {
		if (!valid) return;
		// if (state.ruleForm.id != undefined && state.ruleForm.id > 0) {
		// 	await getAPI(SysOrgApi).apiSysOrgUpdatePost(state.ruleForm);
		// } else {
		// 	await getAPI(SysOrgApi).apiSysOrgAddPost(state.ruleForm);
		// }
		closeDialog();

	});
};

// 导出对象
defineExpose({ openDialog });
</script>
<style scoped lang="scss">
.fl {
	display: flex;

}

.aligning1 {
	flex: 6;
	margin-right: 40px;
}

.aligning2 {
	flex: 4;
}

</style>